function c = spherecoordsinv(sc)
% spherecoordsinv  - compute cartesian coordinates from spherical ones
%
% FORMAT:       c = spherecoordsinv(sc)
%
% Input fields:
%
%       sc          Cx3 sphere coordinates
%
% Output fields:
%
%       c           Cx3 cartesian coordinates
%
% See also: spherecoords

% Version:  v0.7f
% Build:    8110521
% Date:     Nov-05 2008, 9:00 PM CET
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin ~= 1 || ...
   ~isa(sc, 'double') || ...
    ndims(sc) > 2 || ...
    size(sc, 2) ~= 3
    error( ...
        'BVQXtools:BadArgument', ...
        'Bad or missing argument.' ...
    );
end

% computation
sn = sin(sc(:, 2));
c = zeros(size(sc));
c(:, 1) = sc(:, 1) .* sn .* cos(sc(:, 3));
c(:, 2) = sc(:, 1) .* sn .* sin(sc(:, 3));
c(:, 3) = sc(:, 1) .* cos(sc(:, 2));
